Let xm commands use domids with XenAPI
authorTom Wilkie <tom.wilkie@gmail.com>
Thu, 29 Mar 2007 16:09:49 +0000 (17:09 +0100)
committerTom Wilkie <tom.wilkie@gmail.com>
Thu, 29 Mar 2007 16:09:49 +0000 (17:09 +0100)
signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>

tools/python/xen/xm/main.py

index 35d6305b36b3f35f3e46f7c72c5c6cd3df0c11eb..34a3a5d51656083271ad3731948877da1cbbc87d 100644 (file)
@@ -560,11 +560,21 @@ def err(msg):
 def get_single_vm(dom):
     if serverType == SERVER_XEN_API:
         uuids = server.xenapi.VM.get_by_name_label(dom)
-        n = len(uuids)
-        if n > 0:
+        if len(uuids) > 0:
             return uuids[0]
-        else:
-            raise OptionError("Domain '%s' not found." % dom)
+
+        try:
+            domid = int(dom)
+            uuids = [server.xenapi.VM.get_domid(vm_ref)
+                     for vm_ref in server.xenapi.VM.get_all()
+                     if int(server.xenapi.VM.get_domid(vm_ref)) == domid]
+        except:
+            pass
+            
+        if len(uuids) > 0:
+            return uuids[0]
+
+        raise OptionError("Domain '%s' not found." % dom)
     else:
         dominfo = server.xend.domain(dom, False)
         return dominfo['uuid']